﻿@model IEnumerable<ZdSoft.Model.Resource>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<p>
    <a href="javascript:" id="createResourse">创建新课件</a>
    @*@Html.ActionLink("创建新课件", "Create", new { id="createResourse"})*@
    <input type="text" required lay-verify="required" placeholder="请输入搜索内容" autocomplete="off" class="layui-input-block" style="width:480px" />
    <input type="button" value="搜索" class="layui-btn" />
</p>
<table class="layui-table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.ResourcesName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ResourcesType)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ResourcesInfo)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.IsActive)
            </th>
            <th>
                操作
            </th>
        </tr>
    </thead>
    <tbody>
        @{
            if (Model == null || Model.Count() <= 0)
            {
                <tr>
                    <td colspan="6" style="text-align:center">
                        没有数据
                    </td>
                </tr>
            }
            else
            {
                foreach (var item in Model)
                {
                    <tr id=@item.ID>
                        <td>
                            @Html.DisplayFor(modelItem => item.ResourcesName)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.ResourcesType)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.ResourcesInfo)
                        </td>
                        <td>
                            @{
                    if (item.IsActive == "资源上架")
                    {
                        @:资源可用
                        }
                    else
                    {
                        @:资源不可用
                        }
                            }
                        </td>
                        <td>
                            @Html.ActionLink("Edit", "Edit", new { resourceID = item.ID }) |
                            @Html.ActionLink("Details", "Details", new { resourceID = item.ID }) |
                            @Html.ActionLink("Delete", "Delete", new { resourceID = item.ID })
                        </td>
                    </tr>
                }
            }
        }

    </tbody>
</table>
<div id="page"></div>
<script>
    $(function () {
        $("#createResourse").click(function () {
            //自定页
            layer.open({
                type: 2,
                title: "Online Study System",
                skin: 'demo-class', //样式类名
                offset: "20px",
                closeBtn: 0, //不显示关闭按钮
                shift: 2,
                scrollbar: false,
                resize: false,
                area: ['680px', '820px'], //宽高
                shadeClose: false, //开启遮罩关闭
                fixed: true,
                content: ["http://localhost:24833/Resource/Create", 0]
            });
        });

        //a标签的信息，要是是删除或者修改则需要提示
        $("a").click(function () {
            switch ($(this).text().trim()) {
                case "Edit":
                    return confirm("你确认修改吗？"); break;
                case "Delete":
                    return confirm("你确认删除吗？"); break;
                default:
                    break;
            }
        });

        //分页模块

        layui.use('laypage', function () {
            var laypage = layui.laypage;

            //执行一个laypage实例
            laypage.render({
                elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
              , count: @ViewBag.resourceCount  //数据总数，从服务端得到@ViewBag.resourseCount
              , layout: ['count', 'prev', 'page', 'next', 'skip']
              , jump: function (obj,first) {
                  if(!first){
                      $.post("../Resource/Index",{pageSize:obj.limit,pageIndex:obj.curr},function(data){
                          console.log(data);
                          $("tbody").html("");
                          $.each($.parseJSON(data),function(index,obj){
                              //console.log(obj);
                              var tempIsActive= obj.IsActive==true?"资源可用":"资源不可用";
                              var tbodyhtm="<tr>"+
                              "<td>"+
                                  obj.ResourcesName+
                              "</td>"+
                              "<td>"+
                                  obj.ResourcesType+
                              "</td>"+
                              "<td>"+
                                  obj.ResourcesInfo+
                              "</td>"+
                              "<td>"+
                                  tempIsActive+
                              "</td>"+
                              "<td>"+
                                  "<a href='/User/Edit?resourceID="+obj.ID+"'>Edit</a>"+"|"+
                                  "<a href='/User/Details?resourceID="+obj.ID+"'>Details</a>"+"|"+
                                  "<a href='/User/Delete?resourceID="+obj.ID+"'>Delete</a>"+
                              "</td>"+
                          "</tr>";
                              //console.log(tbodyhtm);
                              $("tbody").append(tbodyhtm);
                          });
                      });
                  }
              }
            });
        });
    });
</script>
